#[macro_use]
extern crate rbatis;

use cassie_core::config::config::DbConfig;
use cassie_core::fundation::AppContext;
use rbatis::rbdc::db::Driver;
use rbatis::RBatis;
use rbdc_mysql::driver::MysqlDriver;
use rbdc_mysql::options::MySqlConnectOptions;

pub mod adapter;
pub mod entity;
pub mod interceptor;

/*
初始化DB
*/
pub fn init_database(database: &DbConfig) -> RBatis {
  let rb = RBatis::new();
  let option: MySqlConnectOptions = MySqlConnectOptions::new()
      .database(database.db())
      .host(database.host())
      .port(database.port().unwrap_or(3306))
      .username(database.username())
      .password(database.password());
  let driver: MysqlDriver = MysqlDriver {};
  rb.init_opt(driver, option).expect("database init error");
  return rb;
}
